# https://leetcode-cn.com/problems/palindrome-number/
class Solution:
    def isPalindrome1(self, x: int) -> bool:
        if x < 0:
            return False
        # 获取整数的位数size
        size = 10
        while True:
            if x < size:
                break
            size *= 10
        # 用除法将个位数和首位数弹出后进行比较
        while x:
            if size == 10:
                return True
            x, yr = divmod(x, 10)
            size /= 100
            yl, _x = divmod(x, size)
            x = int(_x)
            if yl != yr:
                return False
        return True

    def isPalindrome2(self, x: int) -> bool:
        if x < 0:
            return False
        elif x == 0:
            return True
        elif x%10 == 0:
            return False
        else:
            revert_num = 0
            while x > revert_num:
                revert_num = revert_num * 10 + x%10
                x //= 10
            return x == revert_num or x == revert_num // 10


if __name__ == "__main__":
    pass
